package com.ithrima.activiti;


import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;

import java.io.InputStream;
import java.util.zip.ZipInputStream;

/**
 * 流程定义部署
 * <p>
 * 部署流程影响的表
 * act_re_deployment
 * act_re_procdef
 */
public class ActivitiDeployment {


    // 压包部署
    public static void main(String[] args) {
        // 1 创建 processEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //2  得到RepositoryServer 实例
        RepositoryService repositoryService = processEngine.getRepositoryService();
        //3.转化处zipInputStream流对象
        InputStream in = ActivitiDeployment.class.getClassLoader().getResourceAsStream("diagram/bpmn.zip");
        // 4. 将inputStream流转化为ZipInputStream流
        ZipInputStream inputStream = new ZipInputStream(in);
        //5.进行部署
        Deployment deploy = repositoryService.createDeployment()
                .addZipInputStream(inputStream)
                .name("请假流程1111111")  // 设置流程名称
                .deploy();
        //6 输出部署信息
        System.out.println(deploy.toString());

    }
//  文件部署
//    public static void main(String[] args) {
//        // 1 创建 processEngine对象
//        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//        //2  得到RepositoryServer 实例
//        RepositoryService repositoryService = processEngine.getRepositoryService();
//        //3.进行部署
//        Deployment deploy = repositoryService.createDeployment()
//                .addClasspathResource("diagram/test.bpmn")
//                .addClasspathResource("diagram/test.png")
//                .name("请假流程")  // 设置流程名称
//                .deploy();
//        //4 输出部署信息
//        System.out.println(deploy.toString());
//    }
}
